package com.kwshare.system.controller;

import com.kwshare.common.core.domain.Response;
import com.kwshare.common.core.domain.system.LoginInfo;
import org.springframework.web.bind.annotation.*;
import service.ElasticSearchService;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 登录日志
 *
 * @author yangjing
 */
@RestController
@RequestMapping("/logininfo")
public class LoginInfoController {

    /**
     * 日志分页列表
     *
     * @param pageNum 页码
     * @param pageSize 页面大小
     * @return  日志记录
     */
    @GetMapping("/list")
    public Response<?> list(int pageNum,int pageSize){
        Map<String, Object> map = null;
        try {
            map = ElasticSearchService.saveLoginInfo(pageNum,pageSize);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Response.ok(map);
    }

    /**
     * 添加登录信息
     *
     * @param loginInfo 用户登录信息
     */
    @PostMapping
    public void add(@RequestBody LoginInfo loginInfo){
        try {
            ElasticSearchService.saveLoginInfo(loginInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
